package com.webproject.model.services;

import java.util.ArrayList;
import java.util.Collection;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import com.webproject.model.bean.CircunstanceBean;
import com.webproject.model.bean.ConsentBean;
import com.webproject.model.bean.DiagnosticBean;
import com.webproject.model.bean.PatientBean;
import com.webproject.model.bean.TreatmentBean;
import com.webproject.model.interfaces.Clinic;

// TODO: Auto-generated Javadoc
/**
 * The Class DummyClinicService.
 */
@Repository
@Transactional
public class DummyClinicService implements Clinic {

	/** The session factory. */
	private SessionFactory sessionFactory;

	/**
	 * Instantiates a new dummy clinic service.
	 * 
	 * @param sessionFactory
	 *            the session factory
	 */
	@Autowired
	public DummyClinicService(SessionFactory sessionFactory) {
		this.sessionFactory = sessionFactory;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.webproject.model.interfaces.Clinic#addConsent(com.webproject.model
	 * .bean.ConsentBean)
	 */
	public void addConsent(ConsentBean consent) throws DataAccessException {
		// TODO Auto-generated method stub

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.webproject.model.interfaces.Clinic#findPatients(com.webproject.model
	 * .bean.PatientBean)
	 */
	@Transactional(readOnly = true)
	@SuppressWarnings("unchecked")
	public Collection<PatientBean> findPatients(PatientBean patientBean)
			throws DataAccessException {
		Collection<PatientBean> collection = new ArrayList<PatientBean>();
		collection.add(getPatient(1));
		collection.add(getPatient(2));
		collection.add(getPatient(3));
		collection.add(getPatient(4));
		collection.add(getPatient(5));
		return collection;
	}

	/**
	 * Gets the circunstances.
	 * 
	 * @return the circunstances
	 */
	private CircunstanceBean getCircunstances() {

		CircunstanceBean bean = new CircunstanceBean();
		bean.setId(9);
		bean.setName("circunstancia");
		bean.setDescription("Nueva circusntancia");
		return bean;
	}

	/**
	 * Gets the consent.
	 * 
	 * @param i
	 *            the i
	 * @return the consent
	 */
	private ConsentBean getConsent(int i) {
		ConsentBean bean = new ConsentBean();
		bean.setId(i);
		bean.setName("consent name");
		bean.setPatient(getPatient(i));
		bean.getTreatments().add(getTreatment(1));
		bean.getTreatments().add(getTreatment(2));
		bean.getTreatments().add(getTreatment(3));
		bean.getTreatments().add(getTreatment(4));
		bean.getTreatments().add(getTreatment(5));
		bean.getDiagnostics().add(getDiagnostic());
		bean.getDiagnostics().add(getDiagnostic());
		bean.getDiagnostics().add(getDiagnostic());
		bean.getCircunstances().add(getCircunstances());
		bean.getCircunstances().add(getCircunstances());
		bean.getCircunstances().add(getCircunstances());
		return bean;
	}

	/**
	 * Gets the diagnostic.
	 * 
	 * @return the diagnostic
	 */
	private DiagnosticBean getDiagnostic() {

		DiagnosticBean bean = new DiagnosticBean();
		bean.setId(5);
		bean.setName("diagnostico");
		bean.setDescription("Nuevo diagnostico");
		return bean;
	}

	/**
	 * Gets the patient.
	 * 
	 * @param i
	 *            the i
	 * @return the patient
	 */
	private PatientBean getPatient(int i) {
		PatientBean bean = new PatientBean();
		bean.setId(i);
		bean.setLastName("lala");
		bean.setName("nene");
		bean.setHistory("y6543");
		return bean;
	}

	/**
	 * Gets the treatment.
	 * 
	 * @param i
	 *            the i
	 * @return the treatment
	 */
	private TreatmentBean getTreatment(int i) {
		TreatmentBean bean = new TreatmentBean();
		bean.setId(i);
		bean.setName("tratamiento");
		bean.setDescription("Nuevo tratamiento");
		return bean;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.webproject.model.interfaces.Clinic#loadConsent(int)
	 */
	public ConsentBean loadConsent(int id) throws DataAccessException {
		return getConsent(id);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.webproject.model.interfaces.Clinic#loadPatient(int)
	 */
	public PatientBean loadPatient(int id) throws DataAccessException {
		return getPatient(id);
	}

}
